package fenetres;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Toolkit;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JProgressBar;

public class LoadProgress extends JFrame {
	
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	
	private JProgressBar p;
	private JPanel       panel;
	private JLabel       msg,text;
	private int          taille;
	private Dimension    d;
	
	
	
	public LoadProgress(int t)
	{
		d= Toolkit.getDefaultToolkit().getScreenSize();
		taille = t;
		p      = new JProgressBar();
		p.setMaximum(t);
		panel = new JPanel();
		msg   = new JLabel();
		text  = new JLabel("Chargement de l'application ...");
		
		panel.setLayout(new BorderLayout());
		panel.setBackground(Color.RED);
		panel.add(msg , BorderLayout.SOUTH);
		panel.add(p, BorderLayout.CENTER);
		panel.add(text, BorderLayout.NORTH);
		
		this.setContentPane(panel);
		this.setBounds((d.width/2)-200, (d.height/2)-50, 400, 100);
		this.setUndecorated(true);
		this.setVisible(true);
	}
	
	
	

	public void progress(int progress,String m)
	{
		p.setValue(progress);
		msg.setText(m);
		if(progress == taille)
		{
			try {
				Thread.sleep(1000);
				msg.setForeground(Color.GREEN);
				msg.setText(m);
				Thread.sleep(1000);
				this.dispose();
			}
			catch (InterruptedException e) {e.printStackTrace();}
			
		} 
	}
}
